import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';
import { UploadTypeEnum } from '/@/components/Form/src/jeecg/components/JUpload';
//列表数据
export const columns : BasicColumn[] = [
/* 	{
		title: '商户类型',
		align: "center",
		dataIndex: 'type_dictText'
	}, */
	/* {
		title: '租户ID',
		align: "center",
		dataIndex: 'tenantid_dictText'
	}, */
	/* {
		title: '城市',
		align: "center",
		dataIndex: 'city'
	}, */
	{
		title: '公司名称',
		align: "center",
		dataIndex: 'shoptitle'
	},
	{
		title: '联系电话',
		align: "center",
		dataIndex: 'concacttel'
	},
	{
		title: '车辆数量',
		align: "center",
		dataIndex: 'extinfors',
		customRender: ({ text, column }) => {
			if (text.indexOf("carNum") > -1) {
				let carNum = JSON.parse(text).carNum
				if (!carNum) {
					carNum = JSON.parse((JSON.parse(text))).carNum
				}
				return carNum;
			} else {
				return ""
			}
		
		
		}
	},
	{
		title: '地址',
		align: "center",
		dataIndex: 'address'
	},
	{
		title: '图片',
		align: "center",
		dataIndex: 'cover',
		customRender: render.renderImage,
	},
/* 	{
		title: '介绍',
		align: "center",
		dataIndex: 'description'
	}, */
	/* {
		title: '其余属性',
		align: "center",
		dataIndex: 'extinfors'
	}, */
];
//查询数据
export const searchFormSchema : FormSchema[] = [
	{
		label: "商户类型",
		field: "type",
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "shopCategory"
		},
		//colProps: {span: 6},
	},
	{
		label: "租户ID",
		field: "tenantid",
		component: 'JSearchSelect',
		componentProps: {
			dict: "sys_tenant,name,id"
		},
		//colProps: {span: 6},
	},
	{
		label: "联系电话",
		field: "concacttel",
		component: 'Input',
		//colProps: {span: 6},
	},
];

//表单数据
export const formSchema : FormSchema[] = [
/* 	{
		label: '商户类型',
		field: 'type',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "shopCategory"
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入商户类型' },
			];
		},
	}, */
	{
		field: 'cityId',
		label: '选择城市',
		component: 'ApiSelect',
		componentProps: ({ formActionType, formModel }) => {
			return {
				//multiple: 多选；不填写为单选
				mode: 'multiple',
				//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
				api: () => defHttp.get({ url: '/coupleUser/getCitysByTenantId' }),
				//数值转成String
				numberToString: true,
				//标题字段
				labelField: 'name',
				//值字段
				valueField: 'id',
				//请求参数
				params: {
				},
				//返回结果字段
				resultField: 'records'
			}

		},
	},
	/* {
	  label: '租户ID',
	  field: 'tenantid',
	  component: 'JSearchSelect',
	  componentProps:{
		 dict:"sys_tenant,name,id"
	  },
	  dynamicRules: ({model,schema}) => {
			return [
				   { required: true, message: '请输入租户ID!'},
			];
	   },
	}, */
	{
		label: '公司名称',
		field: 'shoptitle',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入公司名称!' },
			];
		},
	},
	{
		label: '联系人',
		field: 'concacttelUserName',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入联系人!' },
			];
		},
	},
	{
		label: '联系电话',
		field: 'concacttel',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入联系电话!' },
			];
		},
	},
	{
		label: '经纬度',
		field: 'gis',
		component: 'Input',
		slot: 'lotAndLat',
		required: true
	},
	{
		label: '车辆数量',
		field: 'carNum',
		component: 'Input',
	},

	{
		label: '地址',
		field: 'address',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入地址!' },
			];
		},
	},
	{
		label: '图片',
		field: 'cover',
		component: 'JImageUpload',
		componentProps: {
		},
	},
	{
		label: '介绍',
		field: 'description',
		component: 'JEditor',//TODO 注意string转换问题
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入介绍!' },
			];
		},
	},
	/*  {
		label: '其余属性',
		field: 'extinfors',
		component: 'InputTextArea',//TODO 注意string转换问题
		dynamicRules: ({model,schema}) => {
			  return [
					 { required: true, message: '请输入其余属性!'},
			  ];
		 },
	  }, */
	// TODO 主键隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
];

//子表列表数据
export const bsBasiclayoutShopbinddealerColumns : BasicColumn[] = [
	{
		title: '绑定状态',
		align: "center",
		dataIndex: 'stats_dictText'
	},
	/* {
		title: '商家ID',
		align: "center",
		dataIndex: 'shopid_dictText'
	}, */
	{
		title: '用户',
		align: "center",
		dataIndex: 'userid_dictText'
	},
];
//子表表单数据
export const bsBasiclayoutShopbinddealerFormSchema : FormSchema[] = [
	// TODO 子表隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
	{
		label: '绑定状态',
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "shop_bind_dealer_status"
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入绑定状态!' },
			];
		},
	},
	{
		label: '商家ID',
		field: 'shopid',
		component: 'input',
		show: false
	},
	{
		label: '用户',
		field: 'userid',
		component: 'JSearchSelect',
		componentProps: {
			dict: "bs_userlayout_userinfor,nickName,id"
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入用户ID!' },
			];
		},
	},
];
//子表列表数据
export const coupleShopPdtColumns : BasicColumn[] = [
	{
		title: '发布时间',
		align: "center",
		dataIndex: 'createTime'
	},
	{
		title: '标题',
		align: "center",
		dataIndex: 'title'
	},
	{
		title: '封面图片',
		align: "center",
		dataIndex: 'cover',
		customRender: render.renderImage,
	},
	{
		title: '市场价',
		align: "center",
		sorter: true,
		dataIndex: 'deduction'
	},
	{
		title: '售价',
		align: "center",
		sorter: true,
		dataIndex: 'price'
	},
	{
		title: '成本价',
		align: "center",
		sorter: true,
		dataIndex: 'costprice'
	},
	/* 	{
			title: '商家',
			align: "center",
			dataIndex: 'shopId_dictText'
		}, */
	{
		title: '销量',
		align: "center",
		sorter: true,
		dataIndex: 'salesQuantity'
	},
	{
		title: '已核销',
		align: "center",
		sorter: true,
		dataIndex: 'cancelledNum'
	},
	{
		title: '超时未核销',
		align: "center",
		sorter: true,
		dataIndex: 'uncancelledNum'
	},
	{
		title: '过期时间',
		align: "center",
		sorter: true,
		dataIndex: 'expirationTime'
	},
	/* 	{
			title: '租户',
			align: "center",
			dataIndex: 'tenantId'
		}, */
];
//子表表单数据
export const coupleShopPdtFormSchema : FormSchema[] = [
	// TODO 子表隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
	{
		label: '标题',
		field: 'title',
		component: 'Input',
		required: true
	},
	{
		label: '模拟销量',
		field: 'simulatedSales',
		component: 'Input',
		required: true
	},
	{
		label: '市场价',
		field: 'deduction',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' },
			];
		},
	},
	{
		label: '售价',
		field: 'price',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' },
			];
		},
	},
	{
		label: '成本价',
		field: 'costprice',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true },
				{ pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' },
			];
		},
		required: true
	},
	{
		label: '过期时间',
		field: 'expirationTime',
		component: 'DatePicker',
		componentProps: {
			showTime: true,
			valueFormat: 'YYYY-MM-DD HH:mm:ss'
		},
	},
	{
		label: '封面图片',
		field: 'cover',
		component: 'JImageUpload',
		componentProps: {
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请上传封面图片!' },
			];
		},
	},
	/* 	{
			label: '商家',
			field: 'shopId',
			component: 'JSearchSelect',
			componentProps: {
				dict: "couple_shop,title,id"
			},
		}, */
	{
		label: '轮播图',
		field: 'slideshowImg',
		component: 'JUpload',
		helpMessage: '最多上传8张图片',
		componentProps: {
			fileType: UploadTypeEnum.image,
			maxCount: 8,
		},
		required:true
		
	},
	{
		label: '详情',
		field: 'msg',
		component: 'JEditor',//TODO 注意string转换问题
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入介绍!' },
			];
		},
	},
];
//子表列表数据
export const coupleShopOrderColumns: BasicColumn[] = [
   {
    title: '订单状态',
    align:"center",
    dataIndex: 'orderStatus_dictText'
   },
   {
    title: '商品',
    align:"center",
    dataIndex: 'pdtId_dictText'
   },
   {
    title: '金额',
    align:"center",
    sorter: true,
    dataIndex: 'price'
   },
   {
    title: '下单用户',
    align:"center",
    dataIndex: 'userId_dictText'
   },
   {
    title: '核销状态',
    align:"center",
    dataIndex: 'chargeOffStatus_dictText'
   },
   {
    title: '核销用户',
    align:"center",
    dataIndex: 'chargeOffUser_dictText'
   },
   {
    title: '过期时间',
    align:"center",
    dataIndex: 'expirationTime'
   },
   {
    title: '核销时间',
    align:"center",
    dataIndex: 'chargeOffTime'
   },
   {
    title: '商家',
    align:"center",
    dataIndex: 'shopId_dictText'
   },
];
//子表表单数据
export const coupleShopOrderFormSchema: FormSchema[] = [
  // TODO 子表隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    label: '订单状态',
    field: 'orderStatus',
    component: 'JSearchSelect',
    componentProps:{
       dict:"sys_category,name,id"
    },
  },
  {
    label: '过期时间',
    field: 'expirationTime',
    component: 'DatePicker',
    componentProps: {
       showTime:true,
       valueFormat: 'YYYY-MM-DD HH:mm:ss'
     },
  },
];